package main

import (
	"fmt"
	"reflect"
	"unsafe"
)

type info struct {
	Name string
	age  int
}

func main() {
	in := info{
		Name: "mch",
		age:  20,
	}
	xx := *(*info)(unsafe.Pointer(&in))
	fmt.Println(xx)
	xxx := (*int)(unsafe.Pointer(uintptr(unsafe.Pointer(&in)) + unsafe.Sizeof(in.Name)))
	fmt.Println(xxx, *xxx)
	*xxx = 30
	fmt.Println(in)
	//var ptr *int
	//num := 11
	//ptr = &num
	//fmt.Printf("pointer value %p \n", ptr)
	//
	//ptrInt := uintptr(unsafe.Pointer(ptr))
	//fmt.Println("unsafe.Pointer value:", unsafe.Pointer(ptr))
	//fmt.Printf("uintptr value is %d \n", ptrInt)

	v := reflect.ValueOf(&in)
	fmt.Println(v.Pointer())
	oo := (*string)(unsafe.Pointer(v.Pointer()))
	fmt.Println("oo:", *oo)
	age := (*int)(unsafe.Pointer(v.Pointer() + unsafe.Sizeof(in.Name)))
	*age = 40
	fmt.Println("age=", in)
}
